﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SysUserMgr.aspx.cs" Inherits="InformationSystem.WebSite.Module.AuthorityMgr.SysUserMgr" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">
            var addEmployee = function () {
                var grid = GridPanel1;
                //有脏数据，不允许再次新增行
                if (grid.isDirty()) return;
                grid.getRowEditor().stopEditing();

                grid.insertRecord(0, {
                    isSystemAdmin: false,
                    gradeid: 0
                });
                grid.getSelectionModel().selectRow(0);
                grid.getRowEditor().startEditing(0);
            }

            var removeEmployee = function () {
                var grid = GridPanel1;
                grid.getRowEditor().stopEditing();
                grid.deleteSelected();
                userListStore.save();
            }

            function callback() {
                parent.ResizeFrameHeight(GridPanel1.getHeight());
            }

            function AfterEdit() {
                var s = GridPanel1.getSelectionModel().getSelections();
                var total = GridPanel1.store.getTotalCount()
                for (var i = 1; i < total - 1; i++) {
                    if (GridPanel1.getView().getCell(i, 0).innerText == s[0].data.userid) {
                        s[0].data.userid = '';
                        Ext.Msg.alert('信息：', '用户ID冲突！');
                        return;
                    }
                }
                GridPanel1.save();
            }
        </script>
    </ext:XScript>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server">
        <Listeners>
            <DocumentReady Fn="callback()" />
        </Listeners>
    </ext:ResourceManager>
    <ext:GridPanel ID="GridPanel1" runat="server" Height="400" Title="用户管理" Layout="ContainerLayout">
        <Store>
            <ext:Store ID="userListStore" runat="server" OnBeforeRecordUpdated="BeforeRecordUpdated"
                AutoLoad="true" OnBeforeRecordDeleted="BeforeRecordDeleted" OnBeforeRecordInserted="BeforeRecordInserted"
                OnAfterStoreChanged="AfterStoreChanged">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="userid" Mapping="UserID" Type="String" />
                            <ext:RecordField Name="name" Mapping="UserName" Type="String" />
                            <ext:RecordField Name="isSystemAdmin" Mapping="IsSystemAdmin" Type="Boolean" />
                            <ext:RecordField Name="collegeName" Mapping="CollegeName" Type="String" />
                            <ext:RecordField Name="gradeid" Mapping="GradeID" Type="Int" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Store>
        <Plugins>
            <ext:RowEditor ID="RowEditor1" runat="server" SaveText="保存" CancelText="取消" 
                MonitorValid="true" ErrorSummary="false"  CommitChangesText="请先保存或取消当前操作" ErrorText="错误">
                <Listeners>
                    <AfterEdit Handler="AfterEdit()" />
                </Listeners>
            </ext:RowEditor>
        </Plugins>
        <TopBar>
            <ext:Toolbar ID="Toolbar1" runat="server">
                <Items>
                    <ext:Button ID="Button1" runat="server" Text="新增" Icon="UserAdd">
                        <Listeners>
                            <Click Fn="addEmployee" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button2" runat="server" Text="删除" Icon="UserDelete">
                        <Listeners>
                            <Click Fn="removeEmployee" />
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:Toolbar>
        </TopBar>
        <BottomBar>
            <ext:StatusBar runat="server" Text="双击记录进行编辑">
            </ext:StatusBar>
        </BottomBar>
        <SelectionModel>
            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
            </ext:RowSelectionModel>
        </SelectionModel>
        <ColumnModel>
            <Columns>
                <ext:Column ColumnID="userid" Header="用户ID" DataIndex="userid" Width="100" Sortable="true">
                    <Editor>
                        <ext:TextField ID="TextField1" runat="server" AllowBlank="false">
                            <Listeners>
                                <BeforeShow Handler="javascript:if(TextField1.value!=''){document.getElementById('TextField1').style.display='none';}else{document.getElementById('TextField1').style.display='';}" />
                            </Listeners>
                        </ext:TextField>
                    </Editor>
                </ext:Column>
                <ext:Column ColumnID="username" Header="用户姓名" DataIndex="name" Width="100">
                    <Editor>
                        <ext:TextField ID="TextField2" runat="server" AllowBlank="false" />
                    </Editor>
                </ext:Column>
                <ext:BooleanColumn ColumnID="useradmin" Header="是否系统管理员" DataIndex="isSystemAdmin"
                    Align="Center" Width="100" TrueText="是" FalseText="否">
                    <Editor>
                        <ext:Checkbox runat="server">
                        </ext:Checkbox>
                    </Editor>
                    <PrepareCommand />
                </ext:BooleanColumn>
                <ext:Column ColumnID="college" Header="学院" DataIndex="collegeName" Width="180">
                    <Editor>
                        <ext:ComboBox ID="cmbcollege" runat="server" AllowBlank="true">
                        </ext:ComboBox>
                    </Editor>
                </ext:Column>
                <ext:Column ColumnID="grade" DataIndex="gradeid" Header="年级" Width="80">
                    <Editor>
                        <ext:ComboBox ID="cmbGrade" runat="server" AllowBlank="true" MinChars="1">
                        </ext:ComboBox>
                    </Editor>
                </ext:Column>
            </Columns>
        </ColumnModel>
        <Listeners>
        </Listeners>
        <DirectEvents>
        </DirectEvents>
    </ext:GridPanel>
    </form>
</body>
</html>
